﻿package com.cb.model.objectmodels
{
	/**
	 * @author blackcj.com - Christopher Black - September 13, 2010
	 * 
	 * Resources: 
	 * http://www.emanueleferonato.com/2009/05/18/understanding-how-box2d-manages-boundaries/
	 * http://www.box2d.org/manual.html
	 * http://box2dflash.sourceforge.net/
	 *
	 */
	 
	import flash.events.EventDispatcher;
	import com.cb.model.vo.Object2dVO;
	import com.cb.view.objectviews.Circle2DView;
	import flash.geom.Rectangle;
	import com.cb.Constants;
	import flash.display.Sprite;
	import Box2D.Collision.*;
	import Box2D.Collision.Shapes.*;
	import Box2D.Common.Math.*;
	import Box2D.Dynamics.*;
	import com.cb.model.WorldModel;
	import com.cb.view.objectviews.Wall2DView;
		
	public class Wall2DModel extends EventDispatcher
	{
		private var _wall2DView:Wall2DView;
		private var _object2dVO:Object2dVO;
		
		public function Wall2DModel(boxRect:Rectangle)
		{		
			_wall2DView = new Wall2DView(boxRect);
			_object2dVO = new Object2dVO();
			_object2dVO.bodyDef = new b2BodyDef();
			_object2dVO.bodyDef.userData = _wall2DView;
			_object2dVO.bodyDef.position.Set(boxRect.x/Constants.PHYS_SCALE, boxRect.y/Constants.PHYS_SCALE);
			
			var polyShape = new b2PolygonShape();
			polyShape.SetAsBox(boxRect.width / 2 /Constants.PHYS_SCALE, boxRect.height / 2 /Constants.PHYS_SCALE);
			
			_object2dVO.fixtureDef  = new b2FixtureDef();
			_object2dVO.fixtureDef.shape = polyShape;
			_object2dVO.fixtureDef.friction = 0.3;
			_object2dVO.fixtureDef.restitution = 0.9;
			_object2dVO.fixtureDef.density = 5;
			
			WorldModel.getInstance().add2dObject(_object2dVO);
		}
		
		public function get wall2dView():Wall2DView
		{
			return _wall2DView;
		}
		
		public function get object2dVO():Object2dVO
		{
			return _object2dVO;
		}
	}
}